package com.yangmin.springcloud.controller;

import com.yangmin.springcloud.entities.CommonResult;
import com.yangmin.springcloud.entities.Payment;
import com.yangmin.springcloud.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @Value("${server.port}")
    private String paymentPort;

    @PostMapping("/add")
    public CommonResult<Integer> addPayment(@RequestBody Payment payment) {
        Integer integer = paymentService.insertOnePayment(payment);
        if (integer > 0) {
            return new CommonResult<Integer>("200", "插入成功:8002", integer);
        }
        return new CommonResult<Integer>("500", "插入失败:8002", null);

    }

    @GetMapping("/select/{id}")
    public CommonResult<Payment> selectPayment(@PathVariable("id") Integer id) {
        return new CommonResult<Payment>("200", "查询成功" + paymentPort, paymentService.searchById(id));
    }

    @GetMapping("/getPort")
    public CommonResult<String> getPort() {
        return new CommonResult<String>("200", "success", paymentPort);
    }
}
